package com.example.webchar.webchar.utils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: boot
 * @description
 * @author: YouName
 * @create: 2021-03-24 11:59
 **/
@Service
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private boolean code;
    private String msg;
    private Integer start;
    private Map<String, Object> extend = new HashMap<>();

    public static Result success() {
        Result result = new Result();
        result.setCode(true);
        result.setMsg("成功");
        result.setStart(200);
        return result;
    }

    public Result add(String key, Object value) {
        this.getExtend().put(key, value);
        return this;
    }

    public static Result fail() {
        Result result = new Result();
        result.setCode(false);
        result.setMsg("失败");
        result.setStart(400);
        return result;
    }

    public boolean getCode() {
        return this.code;
    }
}


